package touche.touche;

import model.GameManager;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

public class ToucheToucheActivity extends Activity implements
		View.OnClickListener {
	private Button _buttonPlay;
	private ImageButton _buttonFacebook;
	private ImageButton _buttonTwitter;
	private ImageButton _buttonRate;
	private ImageButton _buttonEmail;
	private Button _buttonScore;
	private Button _buttonHelp;
	private Button _buttonOptions;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		_buttonPlay = (Button) findViewById(R.id.buttonPlay);
		_buttonPlay.setOnClickListener(this);

		_buttonFacebook = (ImageButton) findViewById(R.id.buttonFacebook);
		_buttonFacebook.setOnClickListener(this);

		_buttonTwitter = (ImageButton) findViewById(R.id.buttonTwitter);
		_buttonTwitter.setOnClickListener(this);

		_buttonRate = (ImageButton) findViewById(R.id.buttonRate);
		_buttonRate.setOnClickListener(this);

		_buttonEmail = (ImageButton) findViewById(R.id.buttonEmail);
		_buttonEmail.setOnClickListener(this);

		_buttonScore = (Button) findViewById(R.id.buttonScore);
		_buttonScore.setOnClickListener(this);

		_buttonHelp = (Button) findViewById(R.id.buttonHelp);
		_buttonHelp.setOnClickListener(this);

		_buttonOptions = (Button) findViewById(R.id.buttonOptions);
		_buttonOptions.setOnClickListener(this);
	}

	public void onClick(View v) {
		if (_buttonPlay == v) {
			GameManager.getInstance().start(this);
		} else if (_buttonFacebook == v) {
			Intent i = new Intent(Intent.ACTION_VIEW);
			Uri u = Uri.parse("https://www.facebook.com/ToucheToucheApp");
			i.setData(u);
			startActivity(i);
		} else if (_buttonTwitter == v) {
			Intent i = new Intent(Intent.ACTION_VIEW);
			Uri u = Uri.parse("https://twitter.com/#!/ToucheToucheApp");
			i.setData(u);
			startActivity(i);
		} else if (_buttonRate == v) {
			Intent i = new Intent(Intent.ACTION_VIEW);
			Uri u = Uri.parse("https://www.facebook.com/ToucheToucheApp");
			i.setData(u);
			startActivity(i);
		} else if (_buttonEmail == v) {
			final Intent emailIntent = new Intent(
					android.content.Intent.ACTION_SEND);
			emailIntent.setType("plain/text");
			emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
					new String[] { "jordan.montel@gmail.com" });
			emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
					"Application ToucheTouche");
			emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
					"Cette appli est trop bien !!!");
			startActivity(Intent.createChooser(emailIntent, "Send mail..."));
		} else if (_buttonScore == v) {
			startActivity(new Intent(ToucheToucheActivity.this,
					ScoreActivity.class));
		} else if (_buttonHelp == v) {
			startActivity(new Intent(ToucheToucheActivity.this,
					HelpActivity.class));
		} else if (_buttonOptions == v) {
			startActivity(new Intent(ToucheToucheActivity.this,
					OptionsActivity.class));
		}
	}
}